<template>
  <div class="login_container">
    <!--  粒子特效  -->
    <vue-particles
        color="#fff"
        :particleOpacity="0.8"
        :particlesNumber="80"
        shapeType="circle"
        :particleSize="4"
        linesColor="#fff"
        :linesWidth="2"
        :lineLinked="true"
        :lineOpacity="0.8"
        :linesDistance="150"
        :moveSpeed="2"
        :hoverEffect="true"
        hoverMode="grab"
        :clickEffect="true"
        clickMode="push"
        class="lizi"
    >
    </vue-particles>
    <div class="login_box">
      <!--  头像区域    -->
      <div class="avatar_box">
        <img src="../assets/img/zbl-logo.png" alt="" >
      </div>
      <!--   登录表单区域   -->
      <el-form ref="loginFormRef" :model="user" :rules="loginFormRules" label-width="0px" class="login_form">
        <!--   用户名     -->
        <el-form-item prop="loginName" >
          <el-input v-model="user.loginName" @input="updateInput($event)" prefix-icon="el-icon-user"></el-input>
        </el-form-item>
        <!--   密码     -->
        <el-form-item prop="password">
          <el-input v-model="user.password" @input="updateInput($event)" type="password" prefix-icon="el-icon-view"></el-input>
        </el-form-item>
<!--        <el-form-item prop="imageCode">-->
<!--          <el-input v-model="user.imageCode" placeholder="请输入验证码"  @input="updateInput($event)" type="text0" prefix-icon="el-icon-loading">-->
<!--            <template slot="append">-->
<!--              <img v-on:click="loadImageCode()" id="image-code" alt="验证码">-->
<!--            </template>-->
<!--          </el-input>-->
<!--        </el-form-item>-->
        <label class="block clearfix">
            <span class="block input-icon input-icon-right">
              <div class="input-group">
                <input v-model="user.imageCode" type="text" class="form-control" placeholder="验证码">
                <span class="input-group-addon" id="basic-addon2">
                  <img v-on:click="loadImageCode()" id="image-code" alt="验证码"/>
                </span>
              </div>
            </span>
        </label>
        <!--   按钮区域    -->
        <el-form-item class="btns">
          <div class="btn-login">
            <el-button type="primary" @click="login">登录</el-button>
            <el-button type="info" @click="resetLoginForm">重置</el-button>
          </div>

          <div class="avatar_box_font">
            <h4>
              <span>周边游后台管理系统@designbyZDY</span>
            </h4>
          </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
/*
*  :model="loginForm" js双向绑定数据对象
*  :rule="loginFormRules" js数据验证数据对象
*     trigger: 'blur' 失去焦点时
*     message: '请输入用户名' 提示信息
*  @click="resetLoginForm" 重置按钮重置事件
*  @click="login" 登录按钮 提交前预验证
* */
export default {
  name: "Login",
  mounted:function () {
    let _this = this;
    _this.loadImageCode();
  },
  data(){
    return{
      imageCodeToken: "",
      //这是登录表单的数据绑定对象
      user:{
      },
      loginFormRules:{
        loginName:[
          { required: true, message: '请输入用户名/手机号码', trigger: 'blur' },
          ],
        password:[
          { required: true, message: '请输入密码', trigger: 'blur' },
        ]
      }
    }
  },
  methods:{
    /**
     * 加载图形验证码
     */
    loadImageCode: function () {
      let _this = this;
      _this.imageCodeToken = Tool.uuid(8);
      $('#image-code').attr('src', process.env.VUE_APP_SERVER + '/system/admin/kaptcha/image-code/' + _this.imageCodeToken);
    },
    //更新键盘输入input值
    updateInput(e){
      let _this = this;
      _this.$forceUpdate()
    },
    resetLoginForm(){
      this.$refs.loginFormRef.resetFields();
    },
    login(){
      let _this = this;
      _this.user.imageCodeToken = _this.imageCodeToken;
      _this.user.password = hex_md5(_this.user.password + KEY);
      this.$refs.loginFormRef.validate(vaild =>{
        if (!vaild) return ;
        _this.$ajax.post(process.env.VUE_APP_SERVER+'/system/admin/user/login',_this.user).then(
            (response)=>{
              let resp = response.data;
              if (resp.success){
                Tool.setLoginUser(resp.content);
                _this.$router.push("/welcome")
                _this.$message.success("登录成功")
              }else{
                _this.$message.error("登录失败,请检查用户名和密码")
              }
            });
      })
    }
  }
}
</script>

<style lang="less" scoped>
/*
* class="login_container" 登录组件-首层div样式(背景色)
* gainsboro 灰色样式
* class="login_box" 登录组件-登录框div样式
* class="avatar_box 登录组件-登录框头像div样式
* class="avatar_box_font" 登录组件-登录框系统名称span样式
* class="btns" 登录组件-登录框登录部分样式
* class="btn-login" 登录组件-登录框登录按钮样式
* class="lizi" 粒子特效样式复写
*/

.login_container{
  // .代表类名选择器
  background-color: gainsboro;
  height: 100%;
}
.login_box{
  width: 470px;
  height: 370px;
  background-color: #fff;
  //border-radius边框圆角样式
  border-radius: 20px;
  //阴影处理
  box-shadow: 0 0 10px #ffffff;
  //absolute绝对定位
  position: absolute;
  //居中处理
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  //语法嵌套_登录框头像样式
  .avatar_box{
    height: 150px;
    width: 150px;
    // border增加边框
    border: 1px solid #eee;
    border-radius: 50%;
    // padding边距增加
    padding: 10px;
    //阴影处理
    box-shadow: 0 0 10px #ddd;
    position: absolute;
    left: 50%;
    transform:translate(-50%,-50%);
    background-color: #fff;
    img{
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: #eee;
    }
  }
}
.btns{
  display: flex;
  justify-content: center;
}
.login_form{
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 30px;
  box-sizing: border-box;
}
.btn-login{
  margin: 0 80px 0 80px;
}
.avatar_box_font{
  font-style: inherit;
  color: #dddddd;
}
.lizi{
  height:100%;
  /*重置内外边框为0*/
  margin: 0;
  padding: 0;
}
.input-group-addon {
  padding: 0;
}
</style>